<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gozerlib.utils.auth &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../../index.html" />
    <link rel="up" title="gozerlib.utils" href="index.html" />
    <link rel="next" title="gozerlib.utils.dol" href="dol.html" />
    <link rel="prev" title="gozerlib.utils" href="index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="dol.html" title="gozerlib.utils.dol"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index.html" title="gozerlib.utils"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">gozerlib.utils</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-gozerlib.utils.auth">
<h1>gozerlib.utils.auth<a class="headerlink" href="#module-gozerlib.utils.auth" title="Permalink to this headline">¶</a></h1>
<p>google auth related functions.</p>
<dl class="function">
<dt id="gozerlib.utils.auth.checkuser">
<tt class="descclassname">gozerlib.utils.auth.</tt><tt class="descname">checkuser</tt><big>(</big><em>response</em>, <em>request</em><big>)</big><a class="headerlink" href="#gozerlib.utils.auth.checkuser" title="Permalink to this definition">¶</a></dt>
<dd><p>check for user based on web response. first try google 
otherwise return <a class="reference external" href="mailto:'notath&#37;&#52;&#48;IP">'notath<span>&#64;</span>IP</a>&#8216;</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>response</em> &#8211; response object</li>
<li><em>request</em> &#8211; request object</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">tuple of (userhost, gmail user, gozerwave user , nick)</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.auth.finduser">
<tt class="descclassname">gozerlib.utils.auth.</tt><tt class="descname">finduser</tt><big>(</big><big>)</big><a class="headerlink" href="#gozerlib.utils.auth.finduser" title="Permalink to this definition">¶</a></dt>
<dd>try to find the email of the current logged in user.</dd></dl>

<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59</pre></td><td class="code"><div class="highlight"><pre><span class="c"># gozerlib/utils/web.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; google auth related functions. &quot;&quot;&quot;</span>

<span class="c">## google imports</span>

<span class="kn">from</span> <span class="nn">google.appengine.api</span> <span class="kn">import</span> <span class="n">users</span> <span class="k">as</span> <span class="n">gusers</span>

<span class="k">def</span> <span class="nf">finduser</span><span class="p">():</span>

    <span class="sd">&quot;&quot;&quot; try to find the email of the current logged in user. &quot;&quot;&quot;</span>

    <span class="n">user</span> <span class="o">=</span> <span class="n">gusers</span><span class="o">.</span><span class="n">get_current_user</span><span class="p">()</span>

    <span class="k">if</span> <span class="n">user</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">user</span><span class="o">.</span><span class="n">email</span><span class="p">()</span>

    <span class="k">return</span> <span class="s">&quot;&quot;</span> 

<span class="k">def</span> <span class="nf">checkuser</span><span class="p">(</span><span class="n">response</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        check for user based on web response. first try google </span>
<span class="sd">        otherwise return &#39;notath@IP&#39; </span>

<span class="sd">        :param response: response object</span>
<span class="sd">        :param request: request object</span>
<span class="sd">        :rtype: tuple of (userhost, gmail user, gozerwave user , nick)</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">userhost</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="n">u</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="n">nick</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="n">user</span> <span class="o">=</span> <span class="n">gusers</span><span class="o">.</span><span class="n">get_current_user</span><span class="p">()</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">user</span><span class="p">:</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">email</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s">&#39;USER_EMAIL&#39;</span><span class="p">]</span>

            <span class="k">if</span> <span class="n">email</span><span class="p">:</span>
                <span class="n">userhost</span> <span class="o">=</span> <span class="n">nick</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">!</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">remote_addr</span><span class="p">,</span> <span class="n">email</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">userhost</span> <span class="o">=</span> <span class="n">nick</span> <span class="o">=</span> <span class="s">&quot;notauth@</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">request</span><span class="o">.</span><span class="n">remote_addr</span>

        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="n">userhost</span> <span class="o">=</span> <span class="n">nick</span> <span class="o">=</span> <span class="s">&quot;notauth@</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">request</span><span class="o">.</span><span class="n">remote_addr</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">userhost</span> <span class="o">=</span> <span class="n">user</span><span class="o">.</span><span class="n">email</span><span class="p">()</span> 

        <span class="k">if</span> <span class="ow">not</span> <span class="n">userhost</span><span class="p">:</span>
            <span class="n">userhost</span> <span class="o">=</span> <span class="n">nick</span> <span class="o">=</span> <span class="s">&quot;notauth@</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">request</span><span class="o">.</span><span class="n">remote_addr</span>

        <span class="n">nick</span> <span class="o">=</span> <span class="n">user</span><span class="o">.</span><span class="n">nickname</span><span class="p">()</span>

    <span class="n">u</span> <span class="o">=</span> <span class="n">userhost</span>
    <span class="k">return</span> <span class="p">(</span><span class="n">userhost</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">u</span><span class="p">,</span> <span class="n">nick</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">gozerlib.utils.auth</a><ul>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="index.html"
                                  title="previous chapter">gozerlib.utils</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="dol.html"
                                  title="next chapter">gozerlib.utils.dol</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../../_sources/gozerlib/utils/auth.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="dol.html" title="gozerlib.utils.dol"
             >next</a> |</li>
        <li class="right" >
          <a href="index.html" title="gozerlib.utils"
             >previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" >gozerlib.utils</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>